<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path=request.getContextPath();
%>    

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<link href="/resources/css/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet">
	<script type="text/javascript" src="/resources/js/jquery-3.2.1/jquery.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/jquery.validate.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/localization/messages_zh.js"></script>
	<script type="text/javascript" src="/resources/css/bootstrap-4.3.1/js/bootstrap.js"></script>
</head>
<body>
			<form action="update" method="post" name = "addStu">
			
				<input type = "hidden" class = "sid" name = "id" value="${param.id }">
				  
				  <div class="form-group">
				    <label for="exampleInputPassword1">学生姓名</label>
				    <input type="text" class="form-control"  name = "name">
				  </div>
				  
				  
				   <div class="form-group">
				    <label for="exampleInputPassword1">日期</label>
				    <input type="date" class="form-control" name = "created" >
				  </div>
				  
				  <c:forEach items="${listMaj }" var="major">
				  
				  
					  <div class="form-group form-check">
					    <input type="checkbox" class="form-check-input" name = "ids" value = "${major.id }">
					    <label class="form-check-label" for="exampleCheck1">${major.name }</label>
					  </div>
				  
				  
				  </c:forEach>
				  		  		
				  				  
				  <input type = "button" class="btn btn-primary" onclick = "submitForm()" value = "修改">
			</form>

		<script type="text/javascript">
		
		var id = ${param.id}
			
			$.post("findStu",{id:id},function(msg){
				console.log(msg);
				$("input[name='name']").val(msg.name);
				$("input[name='created']").val(msg.created);
				
				
			},"json")
			$.post("findMaj",{id:id},function(msg){
				console.log(msg);
				for(var i in msg){
				
					$(":checkbox[value = "+msg[i]+"]").attr("checked",true);	
				}
				
			},"json")
		
		 function submitForm(){
				$.post("update",$("form[name=addStu]").serialize(),function(msg){
					
					if(msg > 0){
						alert("修改成功");
						location = "/";
					}else{
						alert("修改失败");
					}
					
				})
				
			} 
		
		
		</script>

</body>
</html>